#pragma once

#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include "common/define/noncopyable.h"

class loop;

class loop_thread : public noncopyable
{
public:
    using init_callback = std::function<void(loop*)>;
public:
    loop_thread(const init_callback &cb = init_callback());
    ~loop_thread();
public:
    loop* start_loop();
    void stop_loop();
private:
    void thread_func();
private:
    std::thread m_thread;
    init_callback m_init_callback;
    loop* m_loop{ nullptr };
    std::mutex m_mutex;
    std::condition_variable m_cond;
};